<!DOCTYPE html>
<html lang="zh-cmn-Hans">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <title>拓深科技</title>
    <meta content="width=device-width, initial-scale=1, maximum-scale=1, user-scalable=no" name="viewport">
    <link href="assets/bootstrap/css/bootstrap.min.css" rel="stylesheet"/>
    <link href="assets/font-awesome/css/font-awesome.min.css" rel="stylesheet"/>
    <link href="assets/ionicons-2.0.1/css/ionicons.min.css" rel="stylesheet"/>
    <link href="assets/plugins/daterangepicker/daterangepicker-bs3.css" rel="stylesheet" />
    <link href="assets/plugins/select2/select2.min.css" rel="stylesheet"/>
    <!--<link href="assets/DataTables-1.10.11/media/css/dataTables.bootstrap.min.css" rel="stylesheet"/>-->
    <link href="assets/AdminLTE/dist/css/AdminLTE.min.css" rel="stylesheet"/>
    <link href="assets/AdminLTE/dist/css/skins/_all-skins.min.css" rel="stylesheet"/>
    <link href="assets/images/log.ico" rel="shortcut icon">
    <link href="assets/ipicture/css/iPicture_location.css" rel="stylesheet" media="screen"/>
    <style>
        .table>tbody>tr>td{
            line-height: 15px;
            font-size: 15px;
        }
    </style>
</head>
<body class="hold-transition skin-red sidebar-mini">
<div class="wrapper">
    <!--顶部导航栏开始-->
    <header id="top_header" class="main-header">
        <!-- Logo -->
        <a href="main_page.html" class="logo">
            <!-- mini logo for sidebar mini 50x50 pixels -->
            <span class="logo-mini"><b>T</b>pson</span>
            <!-- logo for regular state and mobile devices -->
            <span class="logo-lg"><b>T</b>PSON</span>
        </a>
        <!-- Header Navbar: style can be found in header.less -->
        <nav class="navbar navbar-static-top" role="navigation">
            <!-- Sidebar toggle button-->
            <a href="#" class="sidebar-toggle" data-toggle="offcanvas" role="button">
                <span class="sr-only">Toggle navigation</span>
                <span class="icon-bar"></span>
                <span class="icon-bar"></span>
                <span class="icon-bar"></span>
            </a>
            <div class="navbar-custom-menu">
                <ul class="nav navbar-nav">

                    <!-- User Account: style can be found in dropdown.less -->
                    <li class="dropdown user user-menu">
                        <a href="#" class="dropdown-toggle" data-toggle="dropdown">
                            <!--<img src="assets/dist/img/user2-160x160.jpg" class="user-image" alt="User Image">-->
                            <span class="hidden-xs">Administrator</span>
                        </a>
                    </li>
                    <!-- Control Sidebar Toggle Button -->
                </ul>
            </div>
        </nav>
    </header>
    <!--顶部导航栏结束-->
    <!--右侧导航栏开始-->
    <aside class="main-sidebar">
        <!-- sidebar: style can be found in sidebar.less -->
        <section class="sidebar">
            <!-- Sidebar user panel -->
            <!-- sidebar menu: : style can be found in sidebar.less -->
            <ul id="side_bar" class="sidebar-menu">
                <li class="header">导航栏</li>
                <li class="treeview">
                    <a href="main_page.html">
                        <i class="fa fa-dashboard text-red"></i> <span>主页</span>
                    </a>
                </li>

                <li class="treeview">
                    <a href="alert_log.html">
                        <i class="fa fa-warning text-red"></i>
                        <span>报警记录</span>
                    </a>
                </li>
                <li class="treeview">
                    <a href="map_show.html">
                        <i class="fa fa-map-marker text-red"></i>
                        <span>地图展示</span>
                    </a>
                </li>
                <li class="treeview">
                    <a href="#">
                        <i class="fa fa-cog text-red"></i>
                        <span>设备管理</span>
                        <i class="fa fa-angle-left pull-right"></i>
                    </a>
                    <ul class="treeview-menu">
                        <!--<li><a href="router_status.html"><i class="fa fa-circle-o text-yellow"></i>设备状态 </a> </li>-->
                        <li><a href="router_config.html"><i class="fa fa-circle-o text-yellow"></i>设备配置 </a> </li>
                    </ul>
                </li>
                <li class="treeview">
                    <a href="#">
                        <i class="fa fa-chain-broken text-red"></i>
                        <span>监测点配置</span>
                        <i class="fa fa-angle-left pull-right"></i>
                    </a>
                    <ul class="treeview-menu">
                        <li><a href="monitor_config_map_config.html"><i class="fa fa-circle-o text-yellow"></i>地图配置 </a> </li>
                        <li><a href="monitor_config_sensor_type_input.html"><i class="fa fa-circle-o text-yellow"></i>传感器类别设置 </a> </li>
                        <li><a href="monitor_config_monitor_input.html"><i class="fa fa-circle-o text-yellow"></i>监测点配置 </a> </li>
                        <li><a href="monitor_config_export.html"><i class="fa fa-circle-o text-yellow"></i>数据导入导出 </a> </li>
                    </ul>
                </li>

                <li id="sys_log" class="treeview active">
                    <a href="show_log.html">
                        <i class="fa fa-files-o text-red"></i>
                        <span>系统日志</span>
                    </a>
                </li>
            </ul>
        </section>
        <!-- /.sidebar -->
    </aside>
    <!--右侧导航栏结束-->
    <!--内容区开始-->
    <div class="content-wrapper">
        <!-- Content Header (Page header) -->
        <section class="content-header">
            <h1>
                <b>系统日志</b>
            </h1>
            <ol class="breadcrumb">
                <li><a href="main_page.html"><i class="fa fa-dashboard"></i> 主页</a></li>
                <li><a href="show_log.html">系统日志</a></li>
            </ol>
        </section>
        <!-- Main content -->
        <section class="invoice">
            <div id="seleect_and_date_div" class="row">
                <div class="col-md-4" id="log_select_div">
                    <div class="form-group">
                        <label>日志类型</label>
                        <select id="select_log_type" class="form-control select2 log_select" style="width: 100%;"></select>
                    </div>
                </div>
                <div class="col-md-4">
                    <!-- Date range -->
                    <div class="form-group">
                        <label>日期范围</label>
                        <div class="input-group">
                            <div class="input-group-addon">
                                <i class="fa fa-calendar"></i>
                            </div>
                            <input type="text" class="form-control pull-right" id="reservation" onchange="changeDate()" placeholder="最大日期范围">
                        </div>
                    </div>
                </div>
                <div class="col-md-2 ">
                    <button onclick="sendCMD()" style="margin-top: 23px;" class="btn btn-warning btn-block" ><i class="fa fa-bookmark-o"></i>  筛选</button>
                </div>
                <!--<div class="col-md-4" id="user_select_div">-->
                    <!--<div class="form-group">-->
                        <!--<label>用户名</label>-->
                        <!--<select id="select_user_id" class="form-control select2 user_select" style="width: 100%;" ></select>-->
                    <!--</div>&lt;!&ndash; /.form-group &ndash;&gt;-->
                <!--</div>-->
            </div>
            <!--<div class="row no-print">-->
                <!--<div class="col-sm-2">-->
                    <!--<button onclick="exportExcel()" class="btn btn-success btn-block"><i class="fa fa-file-excel-o"></i>  导出到EXCEL</button>-->
                <!--</div>-->
                <!--<div class="col-sm-2 col-sm-offset-8">-->
                    <!--<button onclick="sendCMD()" class="btn btn-warning btn-block" ><i class="fa fa-bookmark-o"></i>  筛选</button>-->
                <!--</div>-->
            <!--</div>-->
            <!-- Table row -->
            <div class="row" style="margin-top: 10px;width: 100%">
                <div class="box box-warning">
                    <div class="box-header">
                        <h3 class="box-title"><b>日志数据显示</b></h3>
                    </div>
                    <div class="box-body">
                        <table id="log_table" class="table table-bordered table-striped" style="width: 100%">
                            <thead>
                                <tr>
                                    <th>日志ID</th>
                                    <th>记录时间</th>
                                    <th>日志类型</th>
                                    <th>操作内容</th>
                                </tr>
                            </thead>
                            <tbody id="log_table_tbody">

                            </tbody>
                        </table>
                       <div class="row col-sm-12">
                           <div class="col-sm-5">
                               <h5>当前第<a id="pageIndex">  0  </a>页总共<a id="totalPage">  0  </a>页共<a id="totalNum">  0  </a>条数据</h5>
                           </div>
                           <div style="margin-left: 20px">
                               <button id="pageNxtBtn" class="btn btn-default pull-right" >下一页</button>
                               </div>
                           <div style="margin-right: 20px">
                               <button id="pagePreBtn" class="btn btn-default pull-right">上一页</button>
                           </div>
                       </div>
                    </div>
                </div>
            </div><!-- /.row -->
        </section><!-- /.content -->
        <div class="clearfix"></div>
    </div><!-- /.content-wrapper -->
    <!--内容区结束-->
    <!--页脚开始-->
    <footer class="main-footer no-print">
        <div class="pull-right hidden-xs">
            <b>Version</b>  3.1.4
        </div>
        <strong>Copyright &copy; 2015-2016 <a href="http://www.tpson.cn/" target="_blank">拓深科技</a>.</strong> All rights reserved.
    </footer>
    <!--页脚结束-->
</div>

<script src="assets/plugins/jQuery/jQuery-2.1.4.min.js"></script>
<script src="assets/bootstrap/js/bootstrap.min.js"></script>
<script src="assets/plugins/select2/select2.full.min.js"></script>
<script src="assets/moment.js"></script>
<script src="assets/plugins/daterangepicker/daterangepicker.js"></script>
<script src="assets/layer-v2.2/layer/layer.js"></script>
<script src="assets/AdminLTE/dist/js/app.min.js"></script>
<script src="assets/AdminLTE/dist/js/demo.js"></script>
<script src="assets/cxSelect-master/js/jquery.cxselect.min.js"></script>
<script src="js/alert_check.js"></script>
<script src="assets/AdminLTE/plugins/daterangepicker/moment.min.js"></script>
<script src="assets/ipicture/js/jquery.ipicture_location.js"></script>
<script>
    var server;
    var startDate = 0;
    var endDate = 0;
    var logType = 0;
    var totalPage = 1;
    var pageIndex = 1;
    var totalNum;
    $(function () {
        var path = document.location.pathname;
        var href = document.location.href;
        if(path =='/'){
            var index = href.indexOf(path,href.indexOf(path)+2);
        }else {
            var index = href.indexOf(path);
        }
        var localPath = href.substring(0,index);
        var localName = path.substring(0,path.substr(1).indexOf('/')+1);
        server = localPath + localName;
        socketInit(server.substring(5));
        //日期点选初始化
        $('#reservation').daterangepicker({
            language:  'zh-CN',
            weekStart: 1,
            todayBtn:  1,
            autoclose: 1,
            todayHighlight: 1,
            startView: 2,
            forceParse: 0,
            showSecond:1,
            minuteStep:1,
        });
        //获取日志类型
        $.ajax({
            url: server + "/xk/xkLog/getLogType",
            async:false,
            success: function (data) {
                var jsonObj = JSON.parse(data).data;
                var typeArr = [];
                for(var key in jsonObj){
                    var obj = {
                        id: key,
                        text: jsonObj[key]
                    };
                   typeArr.push(obj);
                }
                $('#log_select_div').cxSelect({
                    firstTitle:'ALL',
                    selects: ['log_select'],
                    jsonName: 'text',
                    jsonValue: 'id',
                    data:typeArr
                });
            }
        });
        showData(1);
        window.onload = checkAlert(server);
    });

    //日期
    function changeDate() {
        var currentVal = $('#reservation').val();
        var temStartDate,temEndDate;
        temStartDate = currentVal.slice(6, 10) +'-'+ currentVal.slice(0, 2) +'-'+ currentVal.slice(3, 5)+' 00:00:00';
//        var date1 = new Date(temStartDate);
//        startDate = parseInt(date1.getTime()/1000);
        startDate = temStartDate;

        temEndDate =currentVal.slice(19, 23) +'-'+ currentVal.slice(13,15) +'-'+ currentVal.slice(16, 18)+' 23:59:59';
//        var date2 = new Date(temEndDate);
//        endDate = parseInt(date2.getTime()/1000);
        endDate = temEndDate;
    }
    //向服务端提交请求
    function sendCMD() {
            showData(1);
    }
    //上一页
    $('#pagePreBtn').click(function () {
        if(pageIndex > 1){

            showData(--pageIndex);
            console.log(pageIndex);
        }else{
            layer.alert('无效的操作。',{
                closeBtn: 0
            });
        }
    });
    //下一页
    $('#pageNxtBtn').click(function () {
        if(pageIndex <= totalPage){

            showData(++pageIndex);
            console.log(pageIndex);
        }else{
            layer.alert('无效的操作。',{
                closeBtn: 0
            });
        }
    });
    $('#select_log_type').change(function(){
        logType = $('#select_log_type').find("option:selected").text();
    })
    //表格显示
    function showData(pageNum) {
        var index = layer.load(0, {shade: false});
        $('#floor_select').change(function (){})
        var formDatas = new FormData();
        if(startDate){
            formDatas.append("start",startDate);
            console.log(startDate);
        }
        if(endDate){
            formDatas.append("end",endDate);
            console.log(endDate);
        }
        if(logType){
            formDatas.append("logType",logType);
        }
        formDatas.append("pageSize",15);
        formDatas.append("pageNum",pageNum);
        if(startDate <= endDate){
            $.ajax({
                type:"post",
                contentType : false,
                processData:false,
                url: server + '/xk/xkLog/getData',
                data:formDatas,
                success:function (data_in) {
                    $('#log_table_tbody').html("");
                    var jsonObj = JSON.parse(data_in);
                    console.log(jsonObj);
                    totalPage = jsonObj.pages;
                    totalNum = jsonObj.total;
                    $('#pageIndex').text(pageIndex);
                    $('#totalNum').text(totalNum);
                    $('#totalPage').text(totalPage);
                    var datas = jsonObj.data;
                    for(var i in datas){
                        var tr = "";
                        var tempData = [datas[i].id,datas[i].log_time,datas[i].log_type,datas[i].log_detail];
                        for(var j in tempData){
                            if(j == tempData.length-1){
                                tr += "<td ><div style='width: 400px;  font-size: 14px;overflow: hidden;white-space: nowrap;text-overflow:ellipsis;' title='"+tempData[j]+"'>" + tempData[j] + "</div></td>";
                            }else {
                                tr += "<td style='width: 25%' ><div style=' font-size: 14px;overflow: hidden;white-space: nowrap;text-overflow:ellipsis;' title='"+tempData[j]+"'>" + tempData[j] + "</div></td>";
                            }
                        }
                        tr = "<tr>" + tr + "</tr>";
                        $('#log_table_tbody').append(tr);
                    }
                    layer.close(index);
                },
                error:function(){
                    $('#log_table_tbody').html("");
                    layer.close(index);
                    layer.alert('数据为空！',{
                        closeBtn: 0
                    });
                }
            });
        }
        else {
            $('#log_table_tbody').html("");
            layer.close(index);
            layer.alert('数据为空！',{
                closeBtn: 0
            });
        }
    }
    //导出excel
    function exportExcel() {
            window.open(server+"/Excel/SystemLog");
    }
</script>
</body>
</html>